package 链表与双指针.m03.d21.t01;

import 链表与双指针.ListNode;

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) {
 *         val = x;
 *         next = null;
 *     }
 * }
 */
public class Solution {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode A = headA, B = headB;
        ListNode res = null;
        while(A != B) {
            if(A == null) {
                A = headB; 
                B = B.next;
            } else if(B == null) {
                B = headA;
                A = A.next;
            } else {
                A = A.next;
                B = B.next;
            }
        }
        res = A;
        return res;
    }
}